<template>
	<view class="a">
		<goodsList :list="list"></goodsList>
		<view class="over" v-if="flag">
			--------已经到底部了--------
		</view>
	</view>
</template>

<script>
	import goodsList from "../../components/goodsList.vue"
	export default {
		data() {
			return {
				lunbo: [],
				list:[],
				index:1,
				flag:false
			}
		},
		methods: {
			async getList() {
				let res = await this.$myRequest({
					url: "/api/getgoods?pageindex=" + this.index
				})
				this.list = [...this.list, ...res.data.message]
			},
		},
		components:{
			goodsList
		},
		onLoad() {
			this.getList()
		},
		onReachBottom() {
			if(this.list.length<10*this.index){
				return this.flag=true
			}
			this.index++;
			this.getList()
		},
		onPullDownRefresh() {
			this.flag=false;
			this.list=[];
			this.index=1;
			this.getList().then(
			()=>{setTimeout(()=>{uni.stopPullDownRefresh()},1000)},
			(err)=>{alert("刷新失败，错误原因"+err)})
		}
	}
</script>

<style scoped>
.a{
	background:#eee
}
.over{
	font-size: 28rpx;
	text-align: center;
	width: 100%;
	height: 50px;
	line-height: 50px;
}
</style>
